hvm: Fix ioemu Qcow support.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 20 Jun 2007 13:36:11 +0000 (14:36 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 20 Jun 2007 13:36:11 +0000 (14:36 +0100)
Normally by default, SIGUSR2 is not blocked, so the signal masks of
SIGUSR2 in all threads is unblocked.

When creating HVM guest, if we use the Qcow format image file, in the
main thread, Qcow uses SIGUSR2 to be notified of the completion of the
request after it issues an AIO request; in tools/ioemu/block.c:
bdrv_read_em(), in some point between bdrv_aio_read() and
qemu_aio_wait(), Dom0 may send a SIGUSR2 to Qemu immediately to
indicate the completion of an AIO request -- since at the moment
SIGUSR2 in main thread is blocked by qemu_aio_wait_start(), the signal
may be delivered to one non-main thread, causing the signal handler of
SIGUSR2 is invoked, then the main thread hangs in
qemu_aio_wait()->syswait()...

This patch blocks SIGUSR2 at the beginning of Qemu's main(), so it
ensures SIGUSR2 is blocked by default when a new thread is created,
then only the threads that use the signal unblock it.

Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
tools/ioemu/block-raw.c
tools/ioemu/vl.c

index 41c8abb413295fbdddedfc18c0aa102da13357fc..9b01211bbfd42cf76d2887577702f7c41a6c431a 100644 (file)
@@ -166,7 +166,7 @@ typedef struct RawAIOCB {
     struct RawAIOCB *next;
 } RawAIOCB;
 
-static int aio_sig_num = SIGUSR2;
+const int aio_sig_num = SIGUSR2;
 static RawAIOCB *first_aio; /* AIO issued */
 static int aio_initialized = 0;
 
index 696791f13c6608298ce395c8cfc76eac1641914f..02c3bb21a20b452cb082144ff49c1b8ceca670aa 100644 (file)
@@ -7059,6 +7059,18 @@ int main(int argc, char **argv)
 #endif
 
     char qemu_dm_logfilename[128];
+    
+    /* Ensure that SIGUSR2 is blocked by default when a new thread is created,
+       then only the threads that use the signal unblock it -- this fixes a
+       race condition in Qcow support where the AIO signal is misdelivered.  */
+    {
+        extern const int aio_sig_num;
+        sigset_t set;
+
+        sigemptyset(&set);
+        sigaddset(&set, aio_sig_num);
+        sigprocmask(SIG_BLOCK, &set, NULL);
+    }
 
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32